package com.wise.transactionsyn.sample1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;

/**
 * * Spring JdbcTemplate/JdbcDaoSupport
 * <p>
 * JdbcDaoSuport其实调用的还是jdbctemplate的方法
 * <p>
 * 集成 JDBCDaoSupport 内部需要再次DI 它的DataSource或者jdbctemplate
 * ---------------------
 * 作者：键盘侠0923
 * 来源：CSDN
 * 原文：https://blog.csdn.net/leaderrida/article/details/53728340
 * 版权声明：本文为博主原创文章，转载请附上博文链接！
 */
@Repository
public class HelloDaoImpl extends JdbcDaoSupport implements HelloDao {
    private MySessionFactory mySessionFactory;

    @Autowired
    public HelloDaoImpl(DataSource dataSource, MySessionFactory mySessionFactory) {
        setDataSource(dataSource);
        this.mySessionFactory = mySessionFactory;
    }

    @Transactional
    @Override
    public void saveHello() {
        mySessionFactory.getSession().save(null);
        //this.getJdbcTemplate().execute("select * from lr_user");
        //this.getJdbcTemplate().update("insert into user values (?,?,?)",arg1,arg2,arg2);
    }
}
